// pages/community/community.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isloading: false,
    lookactive: true,
    likeactive: true,
    likedata:3,
    headPortraitList:[
      {name:"部落冲突",count:100,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:0,src:'/static/images/headPortrait/0.jpg'},
      {name:"剑与远征",count:10,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:1,src:'/static/images/headPortrait/1.jpg'},
      {name:"我的世界",count:111,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:2,src:'/static/images/headPortrait/2.jpg'},
      {name:"王者荣耀",count:1232,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:3,src:'/static/images/headPortrait/3.jpg'},
      {name:"和平精英",count:1112,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:4,src:'/static/images/headPortrait/4.jpg'},
      {name:"奥奇传说",count:145,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:5,src:'/static/images/headPortrait/5.jpg'},
      {name:"王牌竞速",count:781,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:6,src:'/static/images/headPortrait/6.jpg'},
      {name:"原神",count:581,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:7,src:'/static/images/headPortrait/7.jpg'},
      {name:"奥拉星",count:31,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:8,src:'/static/images/headPortrait/8.jpg'},
      {name:"炉石传说",count:81,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:9,src:'/static/images/headPortrait/9.jpg'},
      {name:"欢乐斗地主",count:981,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:10,src:'/static/images/headPortrait/10.jpg'},
      {name:"阴阳师",count:891,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:11,src:'/static/images/headPortrait/11.jpg'},
      {name:"明日方舟",count:1891,time:'17:00',likeactive: true,collectionactive : true,focusactive : true,id:12,src:'/static/images/headPortrait/12.jpg'},
    ],
    list7:[
      '为了保证游戏的正常运行，带给大家更好的游戏体验，将于16:00- 17:00进行一次停机维护更新，维护期间玩家将无法登录游戏。维护完成后，将为大家发放更新补偿：钻石*300+金币*10w。维护时间视更新情况可能会有调整或延长，详情请关注官方最新动态。',
      '我们将于凌晨1:00—6:00进行停服更新，停服更新期间玩家将无法登录游戏。全服更新完成后，玩家可获得999流星碎片、2999金币更新补偿，补偿将在更新日中午12:00前发放。全服更新时间视版本情况可能会有微调或延时，如遇特殊情况，我们将会额外进行补偿，请关注我们的最新公告。',
      '索敌机制修复上线后，我们一直在分析角色的战斗数据，持续关注玩家的反馈。对于这个改动给大家带来的不便，我们表示非常抱歉。在结合线上战斗数据与大家的反馈进行分析后，我们发现：在先前的测试验证过程中，我们对该改动会影响到的战斗场景考虑不全，因此在分析修复对玩家体验的影响后，我们制定出了不够严谨的改动方案对于这个方案给玩家带来的困扰，我们再次致歉。在未来的测试验证流程中，我们会尽量避免作出部分场景下有玩家体验受损的改动，制定更全面的验证方法，在保证原有体验不受影响的前提下，实现体验的优化对开发组来说，对索敌不明确的问题作出改善，是提高玩家体验中的重要一环，但也是一个艰难长远的目标。开发组会持续接收旅行者们的意见，思考并继续改进索敌相关的方案。',

    ],
    list:[
      {count:7},
      {count:8},
      {count:9}
    ],
    list2:[
    {count:0},
    {count:0},
    {count:0}
  ],
  replyList : [
    '喵喵来啦！喵喵会在每日12:30更新目前用时最短的记录，冲冲冲！用时最短记录（统计于4月16日12：30）',
    '前不久，水水路过轻策庄，不禁怀念起最初探索璃月地图时的欣喜，翻过重岩叠嶂后看到美景的愉悦'
  ]
  
  },
  saveReplyToStorage(replyList) {
    // uni.setStorageSync('cart', JSON.stringify(state.cart))
    wx.setStorageSync('title', replyList)
    // console.log(list)
  },
  saveheadPortraitToStorage(headPortraitList) {
    // uni.setStorageSync('cart', JSON.stringify(state.cart))
    wx.setStorageSync('headPortrait', headPortraitList)
    // console.log(list)
  },
  // methods:{
    tapswitch: function(res){
      // console.log(res.currentTarget.dataset.id)
      // var v =e.item
      // let v = wx.getStorageSync('count')
      // console.log(v)
      if (!wx.getStorageSync('title')) {
        this.saveReplyToStorage(this.data.replyList)
      }
      
      wx.navigateTo({
        url: '/subpackage/comments/comments?count=' + res.currentTarget.dataset.id
      //   events: {
      //     // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
      //     acceptDataFromOpenedPage: function(data) {
      //       console.log(data)
      //     },
      //     someEvent: function(data) {
      //       console.log(data)
      //     }
      //   },
      //   success: function(res) {
      //     // 通过eventChannel向被打开页面传送数据
      //     res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      //   }
      })
    // }
  },

    
  
  // methods:{
    
    getNewsList(){
      this.isloading = true
      wx.showLoading({
        title: '数据加载中',
      })

      var value = wx.getStorageSync('count')
      // console.log(value)
      this.data.list2[0].count = value[value.length-1].count+1;
      this.data.list2[1].count = this.data.list2[0].count+1;
      this.data.list2[2].count = this.data.list2[1].count+1;
      
      this.setData({
        list : [...value, ...this.data.list2]
        // this.saveToStorage(list)
        // list : [].concat.apply(this.data.list,this.data.list2)
      })
      // console.log(this.data.list)
      this.saveToStorage(this.data.list)
      this.isloading = false
      setTimeout(function(){
         wx.hideLoading({})
      },200)

    // }
  },
  updateNewsList(){

    var value = wx.getStorageSync('count')
    // console.log(value)
    this.data.list2[0].count = value[0].count-3;
    this.data.list2[1].count = this.data.list2[0].count+1;
    this.data.list2[2].count = this.data.list2[1].count+1;
    
    this.setData({
      list : [...this.data.list2]
      // this.saveToStorage(list)
      // list : [].concat.apply(this.data.list,this.data.list2)
    })
    // console.log(this.data.list)
    this.saveToStorage(this.data.list)
    wx.stopPullDownRefresh()
  // }
},
  bindShare(){
    wx.showActionSheet({
      itemList: ["分享到微信好友",
      "分享到朋友圈",
      "分享到QQ",
      "分享到微博"],
      success: function(res){
        if(!res.cancel){
          // console.log(res.tapIndex)
          wx.showToast({
            title: '分享中...',
            icon: 'loading',
            duration: 1000//持续的时间
          })
          setTimeout(function(){
            wx.showToast({
              title: "分享成功"
            })
         },1200)

        }
      }
    })
  },
  saveToStorage(list) {
    // uni.setStorageSync('cart', JSON.stringify(state.cart))
    wx.setStorageSync('count', list)
    // console.log(list)
 },
 changeLook(){
   
  if(this.data.lookactive){
    this.setData({
      lookactive : false
    })
  }
  else{
    this.setData({
      lookactive : true
    })
  }
 },
 changeLike(e){
  // console.log(e.currentTarget.dataset.id),
  // console.log(this.data.headPortraitList[e.currentTarget.dataset.id].count)
  var listadd = this.data.headPortraitList;
  // var listRedu = this.data.headPortraitList;
  listadd[e.currentTarget.dataset.id].count =listadd[e.currentTarget.dataset.id].count +1,
  listadd[e.currentTarget.dataset.id].likeactive = false
  // listRedu[e.currentTarget.dataset.id].count =listadd[e.currentTarget.dataset.id].count -2
  // console.log(1)
  // console.log(this.data.headPortraitList[e.currentTarget.dataset.id].likeactive)
  if(!(listadd[e.currentTarget.dataset.id].likeactive)){
    this.setData({
      // likeactive : false,
      headPortraitList : listadd
    })
  }
  else{
    this.setData({
      // likeactive : true,
      // headPortraitList : listRedu
    })
  }

  this.saveheadPortraitToStorage(this.data.headPortraitList)
  //  console.log(this.data.likeactive)
 },

 changeLikeRedu(e){
  // console.log(e.currentTarget.dataset.id),
  // console.log(this.data.headPortraitList[e.currentTarget.dataset.id].count)
  // var listadd = this.data.headPortraitList;
  var listRedu = this.data.headPortraitList;
  // listadd[e.currentTarget.dataset.id].count =listadd[e.currentTarget.dataset.id].count +1
  listRedu[e.currentTarget.dataset.id].count =listRedu[e.currentTarget.dataset.id].count -1
  listRedu[e.currentTarget.dataset.id].likeactive = true
  // console.log(1)
  // console.log(2)
  // console.log(listRedu[e.currentTarget.dataset.id].likeactive)
  if(!(listRedu[e.currentTarget.dataset.id].likeactive)){
    this.setData({
      // likeactive : false,
    })
  }
  else{
    this.setData({
      // likeactive : true,
      headPortraitList : listRedu
    })
  }

  this.saveheadPortraitToStorage(this.data.headPortraitList)
  // this.onPullDownRefresh()
  //  console.log(this.data.likeactive)
 },
//  getToStorage(){
//   wx.getStorage({
//     key: 'count',
//     success (res) {
      
//     }
//   })
//  },
  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // console.log(this.data.headPortraitList)
    if (wx.getStorageSync('headPortrait')) {
      let list = wx.getStorageSync('headPortrait');
      this.setData({
        // likeactive : true,
        headPortraitList : list
      })
    }
    this.saveheadPortraitToStorage(this.data.headPortraitList)
    this.saveToStorage(this.data.list)
    // this.getToStorage()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("下拉刷新")
    var value = wx.getStorageSync('count')
    // console.log(value[0].count === 1)
    if(value[0].count === 1) return wx.showToast({
      title: '已经没有更新的消息了，不要在拉了',
      icon: 'none'
    })
    this.updateNewsList() 
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var value = wx.getStorageSync('count')
    // console.log(value[value.length-1].count)
    if(value[value.length-1].count >= 12) return wx.showToast({
      title: '没有更多了，只能查看最近12小时的数据',
      icon: 'none'
    })
    this.getNewsList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
